package com.sz.biz.app.web.api.system;

import com.sz.biz.app.web.BaseController;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.core.system.entity.SysDict;
import com.sz.common.core.system.service.SysDictService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 */
@RestController
@RequestMapping("/api/v1/dict")
@Api(description = " ", tags = "102、字典服务")
public class SysDictController extends BaseController {
    @Autowired
    private SysDictService sysDictService;

    /**
     * 获取重量单位
     */
    @ApiOperation(value = "获取物流重量单位", notes = "获取所有可用物流重量单位列表")
    @RequestMapping(value = "/unit/weight", method = {RequestMethod.GET})
    public ResultDto getWeightUnits() {
        List<SysDict> units = sysDictService.findByCatalog("sys.unit.weight");
        return new ResultDto(units);
    }


    /**
     * 获取重量单位
     */
    @ApiOperation(value = "获取贸易重量单位", notes = "获取所有可用贸易重量单位列表")
    @RequestMapping(value = "/unit/weight/trade", method = {RequestMethod.GET})
    public ResultDto getTradeWeightUnits() {
        List<SysDict> commonUnits = sysDictService.findByCatalog("sys.unit.weight");
        List<SysDict> tradeUnits = sysDictService.findByCatalog("sys.unit.weight.trade");
        commonUnits.addAll(tradeUnits);
        return new ResultDto(commonUnits);
    }

    /**
     * 获取计价方式
     */
    @ApiOperation(value = "获取计价方式", notes = "获取计价方式")
    @RequestMapping(value = "/price/calctype", method = {RequestMethod.GET})
    public ResultDto getPriceCalcTypes() {
        List<SysDict> dicts = sysDictService.findByCatalog("biz.price.calctype");
        return new ResultDto(dicts);
    }

    /**
     * 获取计量单位
     */
    @ApiOperation(value = "获取计量单位", notes = "获取计量单位")
    @RequestMapping(value = "/unit/base", method = {RequestMethod.GET})
    public ResultDto getGoodsUnit() {
        List<SysDict> dicts = sysDictService.findByCatalog("biz.unit.base");
        return new ResultDto(dicts);
    }

    /**
     * 获取数据字典数据
     */
    @ApiOperation(value = "获取数据字典数据", notes = "获取数据字典数据")
    @RequestMapping(value = "/data", method = {RequestMethod.GET})
    public ResultDto getData(@ApiParam(required = true, examples =
    @Example({
            @ExampleProperty(mediaType = "string", value = "whp1"),
            @ExampleProperty(mediaType = "string", value = "whp2")})) @RequestParam String catalog) {
        List<SysDict> dicts = sysDictService.findByCatalog(catalog);
        return new ResultDto(dicts);
    }
}
